package com.leyou.dto;

import com.leyou.common.dto.BaseDTO;
import com.leyou.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor//为该类提供无参的构造方法
@EqualsAndHashCode(callSuper = false)//此注解会生成equals(Object other) 和 hashCode()方法。
//callSuper = false不调用父类的属性，那么子类属性里面的相同的话，那hashcode的值就相同
public class SpecGroupDTO extends BaseDTO {
    private Long id;
    private Long categoryId;
    private String name;
    private List<SpecParamDTO> params;
    private SpecGroupDTO(BaseEntity entity){
        super(entity);
    }
    public static <T extends BaseEntity>List<SpecGroupDTO> convertEntityList(Collection<T>list){
        if (list==null){
            return Collections.emptyList();
        }
        return list.stream().map(SpecGroupDTO::new).collect(Collectors.toList());
    }

}
